package com.anjie.powerproject.common;

import lombok.Data;

import java.io.Serializable;

/**
 * @author zxy
 * 公共响应包装类
 */
public class Result<T> implements Serializable {
    private T data;
    private boolean success;
    private Integer status;
    private String msg;

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Result() {
    }

    public Result(boolean success, Integer status, String msg) {
        this.success = success;
        this.status = status;
        this.msg = msg;
    }

    public Result(T data, boolean success, Integer status, String msg) {
        this.data = data;
        this.success = success;
        this.status = status;
        this.msg = msg;
    }

    public static <T> Result<T> ok(T data) {
        return new Result<>(data, true, HTTPEnum.SUCCESS.getCode(), HTTPEnum.SUCCESS.getDesc());
    }

    public static <T> Result<T> ok() {
        return ok(null);
    }

    public static <T> Result<T> error(T data, Integer status, String msg) {
        return new Result<>(data, false, status, msg);
    }

    public static <T> Result<T> error(Integer status, String msg) {
        return error(null, status, msg);
    }

    public static <T> Result<T> error(HTTPEnum status) {
        return error(null, status.getCode(), status.getDesc());
    }

    public static <T> Result<T> error(String msg) {
        return error(null, HTTPEnum.FAIL.getCode(), msg);
    }

    public static <T> Result<T> error() {
        return error(null, HTTPEnum.FAIL.getCode(), HTTPEnum.FAIL.getDesc());
    }
}
